﻿
<div class="col-lg-12">
    <div class="space-20 hidden-md hidden-lg"></div>
    <div class="space-4 hidden-sm hidden-xs"></div>
    <select id="state" name="">
        <option selected="" value="-1">待完成</option>
        <option value="1">待配送</option>
        <option value="2">已发货</option>
        <option value="3">已签收</option>
    </select>

    <a href="javascript:void(0)" class="easyui-linkbutton" title="筛选" data-options="iconCls:'icon-search',plain:true,iconAlign:'right'" onclick="searchbtn(this,event)"><input class="input-small" type="text" name="" id="selecttext" value="" placeholder="请输入查询条件" style="vertical-align:middle;line-height:normal;" onclick="searchinput(this)" /></a>
    <div class="space-2"></div>
</div>
<div class="page-content">



    <table id="dg" class="easyui-datagrid" title="个人任务管理" style="width:100%;height:auto" data-options="
							rownumbers:true,
							checkOnSelect:false,
                            url:'/PersonalMsg/Completing/'+@ViewBag.CurrUser.E_ID,
							pagination:true,
							pageSize:10,
							method:'get',
							selectOnCheck:false,
							fitColumns:true,
							singleSelect:true,
							">
        <thead>
            <tr>
                <th data-options="field:'act',formatter:editbtn,align:'center'">操作</th>
                <th data-options="field:'state',width:80,formatter:state,align:'center'">状态</th>
                <th data-options="field:'goodsName',width:80,align:'center'">配送商品</th>
                <th data-options="field:'amount',width:80,align:'center'">数量</th>
                <th data-options="field:'address',width:80,align:'center'">地址</th>
                <th data-options="field:'customer',width:80">用户账号</th>
                <th data-options="field:'phone',width:120">电话号码</th>
                <th data-options="field:'startTime',width:80,align:'center'">下单时间</th>
                <th data-options="field:'endTime',width:80,align:'center'">完成时间</th>
            </tr>

        </thead>
    </table>
    <script type="text/javascript">
        $(function () {
            $(".nav-list li").eq(0).addClass("active");
           

        });


        function editbtn(value, row, index) {

            var _btn = "";
            if (row.state == 1)
                _btn += '<button class="btn btn-danger btn-xs" style="margin:3px;" onclick="send(' + row.id + ',event)">配送</button>';
            else if (row.state >= 3)
                _btn += '<button class="btn btn-danger btn-xs" style="margin:3px;" onclick="assess(' + index + ',event)">查看评价</button>';
            return _btn;
        }


        function searchinput(elem) {
            event.stopPropagation();
            $(elem).select();
        }
        function searchbtn(elem, event) {
            var e = event || window.event;
            e.stopPropagation();
            page(1);
        }


        function send(ID, event) {
            var e = event || window.event;
            e.stopPropagation();
            if (confirm("是否开始配送此订单？")) {

                $.ajax({
                    type: 'post',
                    url: '/PersonalMsg/Send/' + ID,
                    success: function (data) {
                        if (data == 0) {

                        }
                        var pager = $("#dg").datagrid("getPager").pagination("options");

                        page(pager.pageNumber);
                    }
                })
            }

        }

        function assess(index, event) {
            var e = event || window.event;
            e.stopPropagation();
            var row = $("#dg").datagrid("getRows")[index];
            $("#assess").window("open");
            $("#form_assess label span").text(row.grade);
            $("#form_assess textarea").val(row.assess);

        }



        function state(value, row, index) {

            switch (row.state) {
                case 1:
                    return "<span class='red'>待配送</span>";
                    break;
                case 2:
                    return "<span class='green'>待签收</span>";
                    break;
                default:
                    return "<span class='green'>已签收</span>";
                    break;
            }
        }

        function page(_pageNumber) {
            var p = {};
            p.pageNumber = _pageNumber;
            p.pageSize = $("#dg").datagrid("getPager").pagination("options").pageSize;
            p.selecttext = $("#selecttext").val();
            p.state = $("#state").val();
            $.ajax({
                type: 'post',
                url: '/PersonalMsg/Select/'+@ViewBag.CurrUser.E_ID,
                async: true,
                dataType: 'json',
                data: p,
                success: function (data) {
                    $("#dg").datagrid("loadData", data);
                    $("#dg").datagrid("getPager").pagination({
                        onSelectPage: function (pageNumber, pageSize) {
                            page(pageNumber, pageSize);

                        },
                        onRefresh: function (pageNumber, pageSize) {
                            page(pageNumber, pageSize);
                        }
                    });
                }
            });
        }
    </script>
</div>

<div id="assess" class="easyui-window" title="订单评价" style="width:300px;height:200px;display:none;" data-options="iconCls:'icon-add',shadow:false,collapsible:false,minimizable:false,closed:true,modal:false">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'center'" style="text-align:center;">
            <div class="space-10"></div>
            <div id="form_assess">
                <div align="center">
                    <label style="width:150px">评价等级</label>
                    <label style="width:80px"><span></span></label>
                </div>
                <div align="center">
                    <label style="width:150px">评价详情</label>
                    <textarea></textarea>
                   </div>

                <div class="space-10"></div>
                <div style="text-align:center;padding:5px 0">
                    <a href="#" class="easyui-linkbutton" onclick="$('#assess').window('close')" style="width:80px;height:30px">关闭</a>
                </div>
            </div>

        </div>
    </div>
</div>
